using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class SM_OpportunityMap : EntityTypeConfiguration<SM_Opportunity>
    {
        public SM_OpportunityMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Subject)
                .HasMaxLength(100);

            this.Property(t => t.RecordType)
                .HasMaxLength(30);

            this.Property(t => t.RecordID)
                .HasMaxLength(30);

            this.Property(t => t.Rating)
                .HasMaxLength(2);

            this.Property(t => t.Status)
                .HasMaxLength(2);

            // Table & Column Mappings
            this.ToTable("SM_Opportunity");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Subject).HasColumnName("Subject");
            this.Property(t => t.RecordType).HasColumnName("RecordType");
            this.Property(t => t.RecordID).HasColumnName("RecordID");
            this.Property(t => t.EstRevenues).HasColumnName("EstRevenues");
            this.Property(t => t.EstClosureDate).HasColumnName("EstClosureDate");
            this.Property(t => t.Currency).HasColumnName("Currency");
            this.Property(t => t.Probability).HasColumnName("Probability");
            this.Property(t => t.Rating).HasColumnName("Rating");
            this.Property(t => t.Salesman).HasColumnName("Salesman");
            this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
            this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.Notes).HasColumnName("Notes");
            this.Property(t => t.RequiredFrom).HasColumnName("RequiredFrom");

            // Relationships
            this.HasOptional(t => t.currency1)
                .WithMany(t => t.SM_Opportunity)
                .HasForeignKey(d => d.Currency);
            this.HasOptional(t => t.Name)
                .WithMany(t => t.SM_Opportunity)
                .HasForeignKey(d => d.CreatedBy);

        }
    }
}
